home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / browser / ibrowsescripts / rexx / dumpfiles.ibrx < prev    next >
Text File  |  1998-05-24  |  6KB  |  215 lines

  1. /*  $VER: cache.ibrx 1.0     
  2.     Made by Sören Forsberg : sorenf@hem1.passagen.se
  3.   
  4. */
  5. /*
  6. fixa case oberoende i filtyps-sparning
  7. koll om någon anger "http://" som url,eller ingen url alls
  8. */
  9.  
  10. OPTIONS RESULTS
  11. OPTIONS FAILAT 15
  12. call addlib('rexxreqtools.library',0,-30)
  13.  
  14.  
  15.  NL            ='0a'x        /* newline */
  16.  zero        ='00'x        /* zero */
  17.  
  18.  list            ='<PRE>'||NL||'<B>The following files were saved:</B>'||NL||NL
  19.  tot             =20000
  20.  last            =0 
  21.  fonttag         = "rt_font=" || 'topaz' || "/" || 8
  22.  cachepath    ='IBrowse:cache'    
  23.  title        ='Dumpfiles by sorenf@hem1.passagen.se 1998'
  24.  savepath        ='Ram:wwwfiles/'
  25.  levels        =3
  26.  levels_txt    ='Enter number of subdirectories:'
  27. /* path_txt        ='Enter new save-path' */
  28.  what_but        ='_All|_Html|_Gif|_Jpg|_Settings|Cancel'
  29.  tags        ='rt_pubscrname=IBROWSESCREEN'  /* Change here the name of the screen IBROWSE runs */
  30.  noconfig_txt    ='I cannot find the config-file'||NL||'so I guess this is the first time'||NL||'I need you to locate your chache-drawer'
  31.  set_but        ='_Cache|_Save|_Levels|Cancel'    
  32.  edit_txt        ='Choose setting to edit'
  33.  
  34. /* Read configuration, get new cachepath if missing or wrong */
  35.  
  36.  ok=open(configfile,'IBROWSE:REXX/dumpfiles.config','R')
  37. IF ok THEN DO
  38.     cachepath=readln(configfile)
  39.     savepath=readln(configfile)
  40.     levels=readln(configfile)
  41.     close(configfile)
  42. END
  43. IF ~exists(cachepath'globalcache') THEN ok=0
  44. IF ~ok THEN DO
  45.     DO FOREVER
  46.     sel=rtezrequest(noconfig_txt,,title, tags)
  47.     dirname = rtfilerequest('Work:', , "Pick IBrowse Cache directory", ,"rtfi_flags = freqf_nofiles")
  48.     IF rtresult == 0 THEN DO
  49.         call rtezrequest("You didn't pick a directory.", "Exit", ,)
  50.         exit
  51.     END
  52.     if rtresult ~= 0 THEN DO
  53.         cachepath=dirname
  54.         IF exists(cachepath'globalcache') THEN leave
  55.     END
  56.     END      
  57. END
  58.  
  59.  
  60. address 'IBROWSE'
  61. 'QUERY URL'
  62. url = result
  63.  
  64. IF LENGTH(url)<13 THEN DO
  65. sel=rtezrequest('Please use a valid cache-url',,title, tags)
  66. EXIT 
  67. END
  68. /* url='http://hem1.passagen.se/sorenf' */
  69.  
  70.  
  71. htmtest=POS('htm',url)
  72. if htmtest>0 THEN DO
  73.     ch=LASTPOS('/',url)
  74.     url=LEFT(url,ch)
  75. END
  76. /* IF RIGHT(url,1)~='/' THEN url=url||'/' */
  77. urllen= LENGTH(url)
  78.  
  79. parent=LASTPOS('/',url,urllen-1)
  80. IF urllen<8 THEN EXIT
  81. /* Ask the user what to do and let him alter settings if he want */
  82.  
  83. DO FOREVER
  84.     where_txt='Which files should be saved?'||NL||'Cache-path= '||cachepath||NL||'Save-path = '||savepath||NL||'Sub-directorylevels= '||levels||NL||'URL= '||url
  85.     sel=rtezrequest(where_txt,what_but,title,'rtez_defaultresponse=1' tags)
  86.  
  87.     IF sel=5 then Do
  88.         sela=rtezrequest(edit_txt,set_but,title,'rtez_defaultresponse=2' tags)
  89.         IF sela=1 THEN DO
  90.             DO FOREVER
  91.             dirname = rtfilerequest('Work:', , "Pick IBrowse Cache directory", ,"rtfi_flags = freqf_nofiles")
  92.             IF rtresult == 0 THEN DO
  93.                 call rtezrequest("You didn't pick a directory.", "Exit", ,)
  94.                 exit
  95.             END
  96.             IF rtresult ~= 0 THEN DO
  97.                 cachepath=dirname
  98.                 IF exists(cachepath'globalcache') THEN leave
  99.             END
  100.             END      
  101.         END
  102.  
  103.         IF sela=2 THEN DO
  104.             dirname = rtfilerequest('work:', , "Pick a directory", ,"rtfi_flags = freqf_nofiles")
  105.             IF rtresult == 0 THEN DO
  106.                 call rtezrequest("You didn't pick a directory.", "Bummers", , )
  107.             END
  108.             IF rtresult ~= 0 THEN DO
  109.                 savepath=dirname
  110.                 call rtfreefilebuffer()
  111.             END
  112.         END
  113.     
  114.         IF sela=3 THEN DO
  115.         long = rtgetlong(levels, , "Enter a number:",  , "rtgl_min = 1 rtgl_max = 20")
  116.         if rtresult ~=0 then levels=long
  117.         END
  118.     END
  119.     if sel=0 then exit
  120.     if sel<5 then leave
  121. END
  122.  
  123. /* Check with globalcache and save appropiate files */
  124.  
  125. ok=open(infile,cachepath'globalcache','R')
  126. if ~ok then call ErrorMsg("Can't open file!")
  127. input=readch(infile,tot)
  128.     
  129. Do FOREVER
  130. IF last=0 THEN last=1    
  131.  
  132.     hit=POS(url,input,last)                    /* Find a url in cachelist */
  133.     If hit>0 then Do
  134.         last=POS(zero,input,hit)
  135.         mid=last
  136.         last=POS(zero,input,last+1)
  137.         len=last-hit
  138.         yeah=SUBSTR(input,hit,len)
  139.         check=compare(url,yeah)                /* Check if we want it */
  140.         yeahupp=UPPER(yeah)
  141.         IF sel=2 THEN DO
  142.             checkfix=pos('.HTM',yeahupp)
  143.             IF checkfix=0 then check=0
  144.         END
  145.         IF sel=3 THEN DO
  146.             checkfix=pos('.GIF',yeahupp)
  147.             IF checkfix=0 then check=0
  148.         END
  149.         IF sel=4 THEN DO
  150.             checkfix=pos('.JPG',yeahupp)
  151.             IF checkfix=0 then check=0
  152.         END
  153.  
  154.         IF check=urllen+1 THEN DO            /* Yeah let`s take this one */
  155.             bug=SUBSTR(input,hit+urllen,mid)
  156.             bughit=POS('.',bug)
  157.                 IF (SUBSTR(input,mid-1,1)='/') | (bughit=0) THEN DO    /* Add index.html if missing */
  158.                     yeah=SUBSTR(input,hit,mid-hit)                /* /index.html if bug */
  159.                     IF bughit~=0 THEN yeah=yeah||'index.html'
  160.                      IF bughit=0 THEN yeah=yeah||'/index.html'
  161.                     yeah=yeah||SUBSTR(input,mid,last-mid)
  162.                 END
  163.                 ylen=LENGTH(yeah)
  164.                 yeah=RIGHT(yeah,ylen-parent)
  165.                 ylen=LENGTH(yeah)
  166.                 ADDRESS 'COMMAND'
  167.                 split=POS(zero,yeah)
  168.                 target=savepath||LEFT(yeah,split-1)
  169.                 source=cachepath || RIGHT(yeah,ylen-split)
  170.                 rc=0
  171.                 'copy >NIL:' source to target 
  172.                 /*say target*/
  173.                 list=list||'<A HREF=file://localhost/'||target||'> '||target||'</A>'||NL
  174.                 IF rc~=0 THEN DO
  175.                     test=0
  176.                     DO levels                                /* Make X sub-directories */
  177.                         test=POS('/',target,test+1)
  178.                         IF test~=0 then Do
  179.                             drawer=LEFT(target,test-1)
  180.                         IF ~EXISTS(drawer) THEN 'makedir >NIL:' drawer                    
  181.                         END
  182.                     END
  183.                 'copy >NIL:' source 'to' target
  184.                 
  185.                  END
  186.         END
  187.     END
  188.     IF hit>(tot-200) | (hit=0) THEN DO                    /* Take a new bit of cachelist */
  189.         old=RIGHT(input,200)                        /* if needed                */
  190.         new=READCH(infile,tot-200)
  191.         input=old||new
  192.         last=last-(tot-200)
  193.         IF last<1 THEN last=1
  194.     END
  195.  
  196.     IF EOF(infile) & (hit=0) THEN LEAVE                /* Are we done yet?            */
  197.  
  198. END
  199. ADDRESS 'AREXX' 
  200.    close(infile)
  201.  
  202. /* Save current configuration */
  203. config=cachepath||NL||savepath || NL || levels || NL
  204. ok=open(configfile,'IBROWSE:REXX/dumpfiles.config','W')
  205. new=writeln(configfile,config)
  206.  close(configfile)
  207.  
  208. /* Save the list of files and send to IBrowse */
  209. list=list||'</PRE>'
  210. ok=open(resultfile,'RAM:T/dump.html','W')
  211. new=writeln(resultfile,list)
  212.  close(resultfile)
  213. address 'IBROWSE' 'GOTOURL file://localhost/RAM:T/dump.html'
  214.  
  215. EXIT